package com.itheima.bos.web.action;

import com.itheima.bos.domain.Staff;
import com.itheima.bos.service.IStaffService;
import com.itheima.bos.utils.PageBean;
import com.itheima.bos.web.action.base.BaseAction;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by Mr.King on 2017/3/9.
 */
@Component
@Scope(value = "prototype")
public class StaffAction extends BaseAction<Staff>{

    @Autowired
    private IStaffService staffService;




    //接收作废参数
    private String ids;
    public void setIds(String ids) {
        this.ids = ids;
    }

    //新增派送员
    public String staffAdd(){
        staffService.staffAdd(model);
        return "list";
    }

    //条件分页查询
    public String list() throws IOException {
        setPage();
        //调用service完成分页查询
        staffService.pageQuery(pageBean);

        //配置json过滤参数
        String[] arr = new String[]{"detachedCriteria","pageSize","currentPage","decidedzones"};
        toJSON(pageBean,arr);
        return NONE;
    }

    //记录作废
    @RequiresPermissions("staff")
    public String delete(){
        staffService.delete(ids);
        return "list";
    }

    //记录还原
    public String restore(){
        staffService.restore(ids);
        return "list";
    }

    //保存修改
    public String update(){
        staffService.update(model);
        return "list";
    }

    //定区异步请求
    public String findListByAjax() throws IOException {
        List<Staff> list = staffService.findAll();
        String[] arr = new String[]{"decidedzones","telephone","haspda","deltag","station","standard"};
        toJSON(list,arr);
        return NONE;
    }
}
